<?php
/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2018/5/31
 * Time: 下午12:26
 */

namespace console\controllers;

use common\helpers\predis\Predis;
use common\jobs\PromotionUserJob;
use yii\console\Controller;
use yii;

class PromotionUserGroupController extends Controller
{
    /**
     * 绑定用户组
     */
    public function actionBind()
    {
        $sql = "SELECT b.phone,d.group_id FROM mops_user_coupon a JOIN mops_user b ON a.user_id = b.id JOIN mops_coupon c ON a.coupon_id = c.id JOIN mops_coupon_category d ON c.catalog = d.id WHERE d.group_id>0";
        $dataList = Yii::$app->db->createCommand($sql)->queryAll();
        if (count($dataList) > 0) {
            foreach ($dataList as $data) {
                Yii::$app->queue->push(new PromotionUserJob([
                    'phoneNumberOrEmail' => $data['phone'],
                    'groupType' => $data['group_id'],
                    'countryCode' => 'USA'
                ]));
            }
        }
    }

    public function actionCanReceive()
    {
        $sql = "SELECT customer_number from mops_feedback";
        $feedBackUserList = Yii::$app->db->createCommand($sql)->queryAll();
        foreach ($feedBackUserList as $feedBackUser) {
            Predis::getInstance()->getClient()->client->set("canReceive" . $feedBackUser['customer_number'], 1);
        }
    }
}
